﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JSON;

namespace Facebook_Graph_Toolkit.FacebookObjects {
    /// <summary>
    /// Represents an AppRequest on Facebook
    /// </summary>
    public class AppRequest {
        JsonObject data;
        internal AppRequest(JsonObject JO) { data = JO; }
        /// <summary>
        /// Obtain information about an AppRequest
        /// </summary>
        /// <param name="RequestID">Request ID</param>
        /// <param name="AccessToken">Access Token of either the sender or receiver</param>
        public AppRequest(string RequestID, string AccessToken) {
            data = Helpers.WebResponseHelper.GetJsonFromFacebookObject(RequestID, AccessToken);
        }
        /// <summary>
        /// The Facebook Application that is involved in this request
        /// </summary>
        public NameIDPair Application { get { return new NameIDPair((JsonObject)data["application"]); } }
        /// <summary>
        /// The time which this request was created
        /// </summary>
        public DateTime CreatedTime { get { return Helpers.Common.RFC3339ToDateTime((string)data["created_time"]); } }
        /// <summary>
        /// The ID of the request
        /// </summary>
        public string ID { get { return (string)data["id"]; } }
        /// <summary>
        /// The message in this request
        /// </summary>
        public string Message { get { return (string)data["message"]; } }
        /// <summary>
        /// The tracking data in this request
        /// </summary>
        public string TrackingData { get { return (string)data["data"]; } }
        /// <summary>
        /// The user who sent this request
        /// </summary>
        public NameIDPair Sender { get { return new NameIDPair((JsonObject)data["from"]); } }
        /// <summary>
        /// The user who receives this request
        /// </summary>
        public NameIDPair Target { get { return new NameIDPair((JsonObject)data["to"]); } }
    }
}
